<template>
	<view>
		<!-- #ifdef MP-WEIXIN -->
		<view @tap="tosearch">
			<uni-search-bar clearButton="auto" placeholder="请输入关键字" readonly @click='tosearch'></uni-search-bar>
		</view>
		<!-- #endif -->
		<Lines></Lines>
		<view class='list'>

			<!--左侧滑动-->
			<scroll-view scroll-y="true" class='list-left' :style="'height:'+clentHeight+'px;'">
				<view v-for='(item,index) in leftData' class='left-item' @tap="changeLeftTab(index,item.id)"
					:key="index">
					<view class='left-name' :class="activeIndex===index?'left-name-active':''">{{item.name}}</view>
				</view>
			</scroll-view>

			<!--右侧滑动-->
			<scroll-view scroll-y="true" class='list-right' :style="'height:'+clentHeight+'px;'">
				<view class='righ-list' v-for="(item,index) in rightData" :key='index'>
					<block v-for="(k,i) in item">
						<view class='list-title'>{{k.name}}</view>
						<view class='right-content'>
							<view class='right-item' v-for="(j,idx) in k.list" :key="idx">
								<image class='right-img' :src="j.imgUrl" ></image>
								<view class='right-name'>{{j.name}}</view>
							</view>
						</view>
					</block>

				</view>

			</scroll-view>

		</view>
			<Tabbar currentPage="list"></Tabbar>
	</view>
</template>

<script>
	import Lines from '@/components/common/Line.vue'
	import Tabbar from '@/common/Tobbr.vue'
	export default {
		data() {
			return {
				clentHeight: 0,
				activeIndex: 0,
				leftData: [],
				//右侧数据
				rightData: []
			}
		},
		components: {
			Lines,
			Tabbar
		},
		onLoad() {
			this.getData();
		},
		//获取可视高度
		onReady() {
			uni.getSystemInfo({
				success: (res) => {
					this.clentHeight = res.windowHeight
					// #ifdef MP-WEIXIN
					this.clentHeight = res.windowHeight - uni.upx2px(56)

					// #endif
				}
			})
		},
		//原生input输入框点击事件
		onNavigationBarSearchInputClicked() {
			uni.navigateTo({
				url: '../Search/Search'
			})
		},
	
		methods: {
			//请求数据
			async getData(id) {
				//如果点击相同分类不发请求
				if (id == (this.activeIndex + 1)) {
					return;
				}

				let res = await this.$Request({
					url: '/api/goods/list'
				})
		console.log(res);
				
				let	leftData = [];
				let rightData = []
				res.data.data.forEach(v => {
					leftData.push({
						id: v.id,
						name: v.name
					})
					//如果点击id值相同
					if (v.id == (this.activeIndex + 1)) {
						rightData.push(v.data)
					}
				})
				this.leftData=leftData;
				this.rightData=rightData
			},

			tosearch() {
				uni.navigateTo({
					url: '../Search/Search'
				})
			},
			//左侧点击事件
			changeLeftTab(index, id) {
				this.getData(id);
				this.activeIndex = index

			}
		}
	}
</script>

<style scoped>
	.list {
		display: flex;
	}

	.list-left {
		width: 200rpx;
	}

	.left-item {
		border-bottom: 2rpx solid #FFFFFF;
		font-size: 28rpx;
		font-weight: bold;
		background-color: #F7F7F7;
	}

	.left-name {
		padding: 30rpx 6rpx;
		text-align: center;
	}

	.left-name-active {
		border-left: 8rpx solid #49BDFB;
		background-color: #FFFFFF;
	}

	.list-right {
		flex: 1;
		padding-left: 30rpx;
		/* margin-bottom: 52rpx; */
	}

	.list-title {
		font-weight: bold;
		font-size: 30rpx;
		padding: 30rpx 0;
	}

	.right-content {
		display: flex;
		flex-wrap: wrap;
	}

	.right-item {
		width: 150rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 10rpx;
	}

	.right-name {
		font-size: 28rpx;
		padding: 16rpx 0;
	}

	.right-img {
		overflow: hidden;
		width: 150rpx;
		height: 150rpx;
	}
</style>
